import { UserState } from '@renderer/store/modules/user/types'
import axios from 'axios'
import type { RouteRecordNormalized } from 'vue-router'

export interface LoginData {
  userAccount: string
  tenantId: string
  loginVerifyType: number
  userPassword: string
}

export interface LoginRes {
  token: string
  user: UserState
}
export function login(data: LoginData) {
  return axios.post<LoginRes>('/system/login', data, { headers: { 'tenant-id': data.tenantId } })
}

export function logout() {
  return axios.post<LoginRes>('/system/logout')
}

export function editPassword(data: { userId: string; userPassword: string }) {
  return axios.post<boolean>('/system/authUserResetPassword', data)
}

export function getUserInfo(data: { userId: string }) {
  return axios.post<UserState>('/system/authUserDetail', data)
}

export interface companyUserType {
  list: {
    createdDt: string
    updatedDt: string
    createdBy: string
    updatedBy: string
    tenantId: string
    tenantName: string
    contactUserId: string
    contactName: string
    contactMobile: string
    status: number
    domain: string
    identityType: string
    authStatus: number
    purchaseCompanyId: number
    purchaseCompanyName: string
  }[]
}
export function getCompanyUserList(data: { userAccount: string }) {
  return axios.post<companyUserType>('/system/host', data)
}

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/api/user/menu')
}
